package org.zju.demo.service.impl;

import org.zju.demo.model.UserProduct;
import org.zju.demo.service.intf.UserProductIntf;
import org.zju.demo.utils.HibernateUtil;

import java.util.List;

/**
 * Created by admin on 2015/8/27.
 */
public class UserProductImpl implements UserProductIntf {
    public List<UserProduct> findByProductId(int productId) {
        String hql = "from UserProduct where productId=?";
        String[] parameters = {Integer.toString(productId)};
        List<UserProduct> list = HibernateUtil.executeQuery(hql, parameters);
        return list;
    }

    public List<UserProduct> findByUserId(int userId) {
        String hql = "from UserProduct where userId=?";
        String[] parameters = {Integer.toString(userId)};
        List<UserProduct> list = HibernateUtil.executeQuery(hql, parameters);
        return list;
    }

    public List<UserProduct> getProductLastNRecords(int productId, int n) {
        String hql = "from UserProduct where productid=?";
        String[] parameters = {Integer.toString(productId)};
        List<UserProduct> list = HibernateUtil.executeQueryFinalNRecords(hql, parameters, n);
        return list;
    }
}
